package com.live.dengdengtv.fragment;

import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.live.dengdengtv.R;
import com.live.dengdengtv.fragment.ChatFragment;
import com.live.dengdengtv.utils.DpUtil;

/**
 * Created by wyf on 2016/9/22.
 */
public class ChatDialogFragment extends DialogFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState){

        String sendId = getArguments().getString(ChatFragment.C2C_ID);
        View view = inflater.inflate(R.layout.dialog_liveing_chat, container);
        ChatFragment fragment = ChatFragment.newInstance(sendId, false);
        getChildFragmentManager().beginTransaction()
                .add(R.id.fragment_container, fragment).commit();

        return view;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState){
        Dialog dialog = new Dialog(getActivity(), R.style.dialog_info);

        Window dialogWindow = dialog.getWindow();

        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics outMetrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
        lp.width = outMetrics.widthPixels; //设置宽度
        dialogWindow.setAttributes(lp);

        dialogWindow.setGravity(Gravity.BOTTOM);

        dialog.setCancelable(true);
        return dialog;
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            int width = ViewGroup.LayoutParams.MATCH_PARENT;
            int height = DpUtil.dip2px(getActivity(), 300);
            dialog.getWindow().setLayout(width, height);
        }
    }

}
